"""
Copyright 2009, Thomas Dejanovic, Jay Shurtz.
 
This is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this software; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site: http://www.fsf.org.

Logging module for hatch. Should be imported as "from hatch_log import * ".
All hatch modules share the same logger instance.
"""

id = "$Id: hatch_generic_methods.py 667 2010-07-01 00:12:17Z jayshurtz $"
# $URL: http://hatch.googlecode.com/svn/tags/taggle_release_2.2/hatch/hatch_library/hatch_generic_methods.py $
# $Author: jayshurtz $
version = " ".join(id.split()[1:3])


def hatchNodeClassAndName(hatchNode):
    """ Return the class & name of a HatchNode or child class instance.
        'hatchNode' should be a HatchNode or child class instance.
    """
    return hatchNode.__class__.__name__ + "('" + hatchNode.name + "')"

def hatchNodeErrorString(hatchNode, string, delimiter=": "):    # XXX Format like "IOError: [Errno 37] bla bla" instead ?
    """ Formats a string by relating it to a specific HatchNode instance.
        This is useful for specifying nodes & formatting errors raised throughout hatch.
        Note that this is NOT a new error type.
        'hatchNode' should be a HatchNode or child class instance.
        'string' should be the original error string or message.
        'delimiter' delimits the formatted string.
        Returns the formatted string.
    """
    if not string.startswith(delimiter):
        string = delimiter + string
    return hatchNodeClassAndName(hatchNode) + string    # TODO - get first line of traceback [module] for line number & node.


